package com.chase.champagne

import android.content.Context
import android.graphics.Color
import android.os.Build
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.chase.champagne.entity.ChampagneRecord

open class MainRVAdapter(var dataList: List<ChampagneRecord>, var rInfo: RInfo) :
    RecyclerView.Adapter<MainRVAdapter.VH>() {

    class RInfo(
        var rvLayout: Int,
        var time: Int
    )

    inner class VH(itemView: View, rInfo: RInfo) : RecyclerView.ViewHolder(itemView) {
        var cpTime = itemView.findViewById<TextView>(rInfo.time)
    }

    var itemClickListener: ((holder: VH, position: Int) -> Any)? = null
    var itemLongClickListener: ((holder: VH, position: Int) -> Any)? = null

    private lateinit var context: Context

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        context = parent.context
        val view = LayoutInflater.from(context).inflate(rInfo.rvLayout, parent, false)
        return VH(view, rInfo)
    }

    override fun getItemCount(): Int = dataList.size

    override fun onBindViewHolder(holder: VH, position: Int) {
        val champagneRecord = dataList[position]
        Log.d("Chase-MainRVAdapter", dataList.toString())
        holder.cpTime.text = champagneRecord.time

        // Fill content
//        holder.tvWebsite.text = account.website
//        holder.tvUsername.text = account.username
//        account.apply {
//            name?.let {
//                holder.lName.visibility = View.VISIBLE
//                holder.tvName.text = it
//            } ?: let { holder.lName.visibility = View.GONE }
//
//            tel?.let {
//                holder.lTel.visibility = View.VISIBLE
//                holder.tvTel.text = it
//            } ?: let { holder.lTel.visibility = View.GONE }
//
//            qq?.let {
//                holder.lQQ.visibility = View.VISIBLE
//                holder.tvQQ.text = it
//            } ?: let { holder.lQQ.visibility = View.GONE }
//
//            weChat?.let {
//                holder.lWeChat.visibility = View.VISIBLE
//                holder.tvWeChat.text = it
//            } ?: let {
//                holder.lWeChat.visibility = View.GONE
//            }
//
//            email?.let {
//                holder.lEmail.visibility = View.VISIBLE
//                holder.tvEmail.text = it
//            } ?: let { holder.lEmail.visibility = View.GONE }
//        }
//
//        holder.cpBlurLayout.visibility = View.GONE
//        holder.cpBlurLayout.alpha = 0f

        // Set listener
        itemClickListener?.run { this(holder, position) }
        itemLongClickListener?.run { this(holder, position) }
    }
}